<template>
  <div class="app-container">
    <div class="left">
          <el-menu default-active="2" @open="handleOpen" @close="handleClose"
            background-color="#f5f5f5" text-color="#000" active-text-color="#ffd04b">
            <el-menu-item index="1" @click="one()">
              <span slot="title">导航一</span>
            </el-menu-item>
            <el-menu-item index="2" @click="two()">
              <span slot="title">导航二</span>
            </el-menu-item>
            <el-menu-item index="3">
              <span slot="title">导航三</span>
            </el-menu-item>
            <el-menu-item index="4">
              <span slot="title">导航四</span>
            </el-menu-item>
          </el-menu>
    </div>
    <div class="right">
      <router-view/>
    </div>
  </div>
</template>

<script>
import { listAccount, getAccount, delAccount, addAccount, updateAccount } from "@/api/carService/account";

export default {
  name: "Account",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车服账户表格数据
      accountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        money: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    one(){
      this.$router.push({ path: '/401' });
    },
    two(){
      this.$router.push({ path: '/404' });
    },

    /** 查询车服账户列表 */
    getList() {
      this.loading = true;
      listAccount(this.queryParams).then(response => {
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        accId: null,
        name: null,
        money: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.accId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车服账户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const accId = row.accId || this.ids
      getAccount(accId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车服账户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.accId != null) {
            updateAccount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAccount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const accIds = row.accId || this.ids;
      this.$modal.confirm('是否确认删除车服账户编号为"' + accIds + '"的数据项？').then(function () {
        return delAccount(accIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('carService/account/export', {
        ...this.queryParams
      }, `account_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.app-container {
  display: flex;
  margin: 0;
  padding: 0;
  height: 664px;
}

.left {
  background-color: #f5f5f5;
  height: 100%;
}

.right {
  width: calc(100% - 200px);
  margin: 20px;
  border: 1px solid #c9c9c9;
  padding: 20px;
}
</style>